using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using LocalizeMe.ResourceTool.VSObjects;

namespace LocalizeMe.ResourceTool.Analyzers
{
    class DescriptionAttributeAnalyzer:Analyzer
    {
        public DescriptionAttributeAnalyzer(string fileName)
            : base()
        {
            this.FileName = fileName;
        }

        public override System.Data.DataTable GetDatas()
        {
            if (string.IsNullOrEmpty(this.FileName) || !File.Exists(this.FileName))
                return null;

            Regex regex = new Regex(
                      "namespace\\s*(?<NamescaceName>.*$)|class\\s*(?<ClassName>\\w" +
                      "*)|\\[(?<AttributeName>LocalDescription)\\(\"(?<Key>[^\"]*)\"\\)" +
                      "\\]|(?<Visibility>public){1}\\s*(?<Type>\\w*(\\<\\w*>)?)\\s*" +
                      "(?<PropertyName>[^\\n\\r]*)",
                    RegexOptions.Multiline
                    | RegexOptions.CultureInvariant
                    );

            StreamReader sr = new StreamReader(this.FileName);
            string fileContent = sr.ReadToEnd();
            sr.Dispose();

            MatchCollection matches = regex.Matches(fileContent);

            List<VSNamespace> namespaces;
            VSNamespace currentNamespace = null ;
            string currentClass = string.Empty;
            string property = string.Empty;

            foreach (Match m in matches)
            {
                if (m.Groups["NamespaceName"].Success)
                {
                    if (currentNamespace == null || !currentNamespace.Name.Equals(m.Groups["NamespaceName"].Value))
                    {
                        if (namespaces == null)
                            namespaces = new List<VSNamespace>();
                        namespaces.Add(currentNamespace);
                        currentNamespace = new VSNamespace(m.Groups["NamespaceName"].Value);
                    }
                }
                
                if (m.Groups["ClassName"].Success)
                {
                }

                if (m.Groups["AttributeName"].Success)
                {
                }

                if (m.Groups["Key"].Success)
                {
                }

                if (m.Groups["Visibility"].Success)
                {
                }

                if (m.Groups["Type"].Success)
                {
                }

                if (m.Groups["PropertyName"].Success)
                {
                }
            }
                

            return null;
        }
    }
}
